package controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pojo.Customer;
import service.CustomerManger;
import service.impl.CustomerMangerFactory;

@Controller
public class CustomerController {
	private CustomerManger manager;
	
	public CustomerController() {
		
		manager =CustomerMangerFactory.getInstance();
	}
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST)
	public String addCustomer(Customer c){
		System.out.println(c);
		
		manager.addCustomer(c);
		
		return "redirect:/listAll";
	}
	
	@RequestMapping(value="/listAll")
	public String findAllCustomers(Model model){
		List<Customer> customers=manager.findAllCustomers();
		model.addAttribute("customers", customers);
		return "customers_show";
	}
	@ResponseBody
	@RequestMapping(value="/testJson")
	public Customer addCustomer1(){
		
		Customer c=new Customer();
		c.setSal(23.45);
		c.setCname("JohnYu");
		c.setSex(true);
		
		return c;
	}
	
	
	
	
	
}














